import * as React from 'react'
import {compose} from 'recompose'
import {curry} from 'ramda'

export default curry((functions: Array<Function>, ComposedComponent: React.Component) => {
    return class ComponentDidMount extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                newProps: {}
            }
        }

        componentDidMount() {
            let props = {};
            for (const func of functions || []) {
                const ret = func(this.props)
                props = ret ? {...ret, ...props} : props
            }
            this.setState({newProps: props})
        }

        render() {
            return (<ComposedComponent {...this.props} {...this.state.newProps} />)
        }
    }
})